﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SilverlightCairngorm.Control;
using PowerArrow.nasa.Control;

namespace PowerArrow.nasa.View.Compont
{
    public partial class Arrow : UserControl
    {
        public Arrow()
        {
            // Required to initialize variables
            InitializeComponent();

            this.Loaded += new RoutedEventHandler(Arrow_Loaded);
        }

        void Arrow_Loaded(object sender, RoutedEventArgs e)
        {
            sb_shot.Completed += new EventHandler(sb_shot_Completed);
        }

        void sb_shot_Completed(object sender, EventArgs e)
        {
            ChkResult();
        }

        private void ChkResult()
        {
            CairngormEvent cgEvt = new CairngormEvent(PowerArrowController.CHK_EVENT_RESULT);
            cgEvt.dispatch();
            //sb_shot.Pause();
        }

        #region StatusProperty
        public string Status
        {
            get { return (string)GetValue(StatusProperty); }
            set { SetValue(StatusProperty, value); }
        }
        public static readonly DependencyProperty StatusProperty = DependencyProperty.Register("Status", typeof(string), typeof(Arrow), new PropertyMetadata("General", OnStatusPropertyChanged));

        private static void OnStatusPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            Arrow arr = d as Arrow;
            arr.StatusChanged((string)e.NewValue);
        }

        private void StatusChanged(string s)
        {
            VisualStateManager.GoToState(this, s, true);
        }
        #endregion

        #region FireProperty
        public bool Fire
        {
            get { return (bool)GetValue(FireProperty); }
            set { SetValue(FireProperty, value); }
        }
        public static readonly DependencyProperty FireProperty = DependencyProperty.Register("Fire", typeof(bool), typeof(Arrow), new PropertyMetadata(false, OnFirePropertyChanged));
        private static void OnFirePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            Arrow arr = d as Arrow;
            arr.FireChanged((bool)e.NewValue);
        }
        private void FireChanged(bool f)
        {
            if (f == true)
            {
                sb_shot.Begin();
            }
            else {
                sb_shot.Stop();
            }
        }
        #endregion

        #region IsShowProperty
        public bool IsShow
        {
            get { return (bool)GetValue(IsShowProperty); }
            set { SetValue(IsShowProperty, value); }
        }
        public static readonly DependencyProperty IsShowProperty = DependencyProperty.Register("IsShow", typeof(bool), typeof(Arrow), new PropertyMetadata(true, OnIsShowPropertyChanged));
        private static void OnIsShowPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            Arrow arr = d as Arrow;
            arr.IsShowChanged((bool)e.NewValue);
        }
        private void IsShowChanged(bool f)
        {
            if (f)
            {
                this.Visibility = Visibility.Visible;
            }
            else {
                this.Visibility = Visibility.Collapsed;
            }
        }
        #endregion
    }
}